<template>
  <div
    class="login"
    v-loading="loading"
    element-loading-text="正在登录中"
  ></div>
</template>
<script>
import { softwareloginApi } from "@/api/loginApi";
import { getMenuList } from "@/api/menuApi.js";
import { getURLParameters } from "@/utils/utils.js";
import { currentURL } from "@/utils/utils.js";

export default {
  data() {
    return {
      loading: true
    };
  },
  created() {},
  mounted() {
    this.login();
    // 解码用
    //decodeURIComponent(str)
    // 编码用
    //encodeURIComponent(str)
  },
  methods: {
    // 登录
    login() {
      let url = currentURL();
      let data = getURLParameters(decodeURIComponent(url));
      softwareloginApi({
        gscode: data.gscode,
        guestcode: data.reguserno,
        operators: data.soperator
      }).then(res => {
        let udata = JSON.parse(res.data);
        if (res.code === 0) {
          this.$store.dispatch("user/setUserInfo", udata);
          this.$store.dispatch("user/setLoginStatus", true);
          getMenuList();
          sessionStorage.setItem(
            "user_store",
            JSON.stringify(this.$store.state)
          );
          setTimeout(() => {
            this.loading = false;
            this.$router.push("/dashboard/console");
          }, 1000);
        } else {
          this.loading = false;
          this.$message.error("登录失败，请核对账号密码");
        }
      });
    }
  }
};
</script>
<style lang="scss" scoped>
.login {
  width: 100%;
  height: 100vh;
}
</style>
